

class CircleJoinPanel extends BasePanel {


    lab_nulltip: eui.Label;
    //加入圈子_按钮
    btn_join: eui.Group;
    //底部描述_文字
    lab_info: eui.Label;
    //圈子列表
    group_list: eui.Group;
    //
    img_nulltip: eui.Image;
    /**描述文案*/
    lab_cirlc_desc: eui.Label;

    scroller: eui.Scroller;

    static state: string = "list";

    constructor() {
        super();
        this.skinName = "CircleJoinPanelSkin";
    }

    // ui: CircleJoinUI;

    data: any;

    createChildren() {
        super.createChildren();
        this.btn_join.addEventListener(egret.TouchEvent.TOUCH_TAP, this.click_join, this);
        gameManager.i.addEventListener(GameEventType.Circle_2012, this.update, this);
        gameManager.i.addEventListener(GameEventType.Circle_2013, this.update, this);
    }


    update(data: any) {

        this.clean();

        this.data = data;

        switch (CircleJoinPanel.state) {

            case "list": // 圈子列表

                var i;

                for (i = 0; i < data.self.length; i++) {
                    data.self[i].flag = 1;
                    this.createItem(data.self[i]);
                }
                for (i = 0; i < data.other.length; i++) {
                    data.other[i].flag = 0;
                    this.createItem(data.other[i]);
                }

                if (data.self.length == 0 && data.other.length == 0) {

                    this.lab_nulltip.text = "您当前还没有任何圈子";
                    this.img_nulltip.visible = true;
                    this.lab_cirlc_desc.text = GameConfig.circleDescJoin;
                    this.lab_cirlc_desc.visible = true;
                } else {
                    this.lab_nulltip.text = "";
                    this.img_nulltip.visible = false;
                    this.lab_cirlc_desc.visible = false;
                }
                this.lab_info.text = GameConfig.circleDescJoinBottom;
                this.showLevelDialog(this.data.leave);

                break;
            case "result": //查询后的列表
                this.createItem(data);
                break;
            default:
                break;
        }

    }

    //显示提示面板队列 leave 队列 里面是对象 对象是id（圈子的id）type（1被移除 2自己申请的退出）
    showLevelDialog(leave: any) {

        if (leave.length) {

            var message: string = "";

            for (var i = 0; i < leave.length; i++) {

                message += `您已经离开了${leave[i].name}\n`;

            }

            EffectTextUtils.showTips(message, 4);
            game.askPanel.showMsg(function () { }, message, null, null, true);
        }
    }

    getLevelMessage(level_child: any) {

        var message = '';

        switch (level_child.type) {
            case 1:
                message = '您被圈主移除了圈子';
                break;
            case 2:
                message = '您申请离开圈子成功';
                break;
        }
        return message;
    }


    createItem(data: any) {
        var item = new CircleJoinItem;
        item.parentDialog = this;
        item.update(CircleJoinPanel.state, data);
        this.group_list.addChild(item);
    }


    clean() {

        this.scroller.stopAnimation();
        this.group_list.scrollV = 0;
        this.group_list.removeChildren();

    }

    //加入圈子点击
    click_join() {
        gameManager.viewManager.open("CircleJoinPassPanel", false);
    }

    public hide(): void {
        CircleJoinPanel.state = "list";
        if (this.skinState == "result") {
            Circle.circle_send(2012, { uid: game.player.uid });
        } else {
            super.hide();
        }
    }
    public show(): void {

        super.show();

        this.clean();

        this.skinState = CircleJoinPanel.state;

        /* if(CircleJoinDialog.state == "list") {
             SocketManager.getInstance().getGameConn().send(2012, {uid: GlobalData.getInstance().player.uid});
         }*/
    }
}